//
//  BKUserUnitRequestAPI.m
//  bestkeep
//
//  Created by windCould on 16/11/17.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKUserUnitRequestAPI.h"
#import "BKUserMobileConfigInfo.h"
#import "UT_User.h"
#import "BKUserStatusInfo.h"
#import "BKUserRequestUrl.h"
#import "BKMyCommon.h"
#import "MJExtension.h"
#import "BKUserMyFavorGoodsModel.h"
#import "BKUserCollectionGoodsModel.h"
#import "Sign.h"
#import "Mediator+BKMy.h"
//#import "BKUserBaseInfoModel.h"

#define UTOUU_Tag @"utouu.com"
#define BestKeep_Tag @"bestkeep.cn"

@implementation BKUserUnitRequestAPI

//获取ST
+(void)getSTWithTGT:(NSString *)tgt service:(NSString *)service completeBlock:(BKUserThirdReturnValueBlock)finishBlock
{
    
    if (service == nil) {
        
        service = @"http://api.test.utouu.com/v2/user/data";
    }
    
    [UT_User getSTWithTGT:tgt service:service callBack:^(NSString * ST, NSError * error) {
        
        NSString * st = ST;//(NSString *)data;//[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        if (st || ![st isEqualToString:@""]) {
            NSLog(@"st 获取成功！");
            BKUserStatusInfo * userStatusInfo =[BKUserStatusInfo currentUser];
            
            [userStatusInfo.realm beginWriteTransaction];
            
            userStatusInfo.LoginST = st;
            [userStatusInfo.realm commitWriteTransaction];
        
            finishBlock(nil,ST,nil);
            
        } else {
            
            NSString * tip = @"获取ST失败";
            if (error) {
                
                //[HUD showErrorMessage:error.localizedDescription];
            } else {
                
                [[Mediator sharedInstance]userLoginOut];
            }
            
            finishBlock(tip,nil,error);
        }
        
    }];
}

//用户登录
+(void)userLoginWithUserNum:(NSString *)userNum password:(NSString *)password showTiPInView:(UIView *)view compeleteBlock:(BKUserCompleteBlock)finishBlock
{
    
    
    BKUserMobileConfigInfo * mobileConfig = [[BKUserMobileConfigInfo alloc]init];
    [UT_User loginWithUserName:userNum password:password deviceUDID:mobileConfig.device_udid deviceType:mobileConfig.device_type deviceToken:mobileConfig.device_token version:mobileConfig.version appName:mobileConfig.app_name callBack:^(id responce, NSError *error) {
        
        [BKIndicationView dismiss];
        if (error) {
            
            [HUD showErrorMessage:error.localizedDescription];
        } else {
            
            BOOL result = [[responce objectForKey:@"success"] boolValue];
            NSLog(@"%@",[responce objectForKey:@"msg"]);
            if (![responce objectForKey:@"msg"]) {
               
                [HUD showErrorMessage:@"服务器端发生错误"];
            } else if (result) {
                
                NSString * tgt = [[responce objectForKey:@"data"]objectForKey:@"tgt"];
                BKUserStatusInfo * userStatusInfo =[BKUserStatusInfo currentUser];
                
                [userStatusInfo.realm beginWriteTransaction];
                
                userStatusInfo.userNum = userNum;
                userStatusInfo.userPwd = password;
                userStatusInfo.TGT = tgt;
                
                [userStatusInfo.realm commitWriteTransaction];
                
                //获取st
                [BKUserUnitRequestAPI  getSTWithTGT:tgt service:@"http://api.utouu.com" completeBlock:^(id obj, NSString *st, NSError *error) {
                
                    if (st) {
                        
                        //获取用户信息
                        [BKUserUnitRequestAPI getUserInfoCompleteBlock:^(id obj, NSError *error) {
                            
                            finishBlock(obj,error);
                        }];
                    } else {
                      
                       /*
                        if (error) {
                            
                            //[HUD showErrorMessage:error.localizedDescription];
                        } else {
                            
                            [[Mediator sharedInstance]userLoginOut];
                        }
                        */
                }
                    
                }];
            } else {
                
                NSString * resultStr = [responce objectForKey:@"msg"];
                [HUD showErrorMessage:resultStr];
            
            }
            
        }
    }];
    
}

//获取用户支付密钥
//{
//    "success": "true/false成功/失败",
//    "msg": "xxx返回消息",
//    "code": "xxx返回编码",
//    "data":
//    {
//        "secretKey": "xxxxx",
//    }
//}
+ (void)getUserSecretBlock:(BKUserCompleteBlock)userSecretBlock {
    
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserSecret];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        NSDictionary *dic = responseObject;
        if ([dic[@"success"] boolValue]) {
            userSecretBlock(dic,nil);
            
        }else {
            userSecretBlock(nil,nil);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        userSecretBlock(nil,error);
    }];
    
}

//获取用户信息
+(void)getUserInfoCompleteBlock:(BKUserCompleteBlock)finishBlock
{
    NSString * urlStr = [UTOOUAPIStr stringByAppendingString:UserBaseInfoStr];
    BKUserStatusInfo * userInfo = [BKUserStatusInfo currentUser];
    if (IsNilString(userInfo.LoginST)) {
        
        [self getSTWithTGT:userInfo.TGT service:urlStr completeBlock:^(id obj, NSString *stStr, NSError *error) {
            
            if (stStr) {
                
                NSString * st = stStr;
                
                BKUserStatusInfo * userStatusInfo = [BKUserStatusInfo currentUser];
                [userStatusInfo.realm beginWriteTransaction];
                userStatusInfo.LoginST = st;
                userStatusInfo.isLogin = YES;
                [userStatusInfo.realm commitWriteTransaction];
                NSLog(@"st获取成功！");
                
                [[NSNotificationCenter defaultCenter]postNotificationName:UserDidLoginNotification object:nil];
                [self getUserInfoWith:st block:^(id obj, NSError *error) {
                    
                    // BKUserBaseInfoModel * model = obj;
                    // finishBlock(model,nil);
                }];
                
                
            } else {
                
                NSString * tipStr = obj;
                NSLog(@"%@",tipStr);
                return ;
            }
            
        }];
        
        
    } else {
        
        
        [self getUserInfoWith:userInfo.LoginST block:^(id obj, NSError *error) {
            
            finishBlock(obj,error);
        }];
        
    }
    
}

+(void)getUserInfoWith:(NSString *)st block:(BKUserCompleteBlock )finishBlock
{
    NSString * requestUrlStr = [UTOOUAPIStr stringByAppendingString:UserBaseInfoStr];
    
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:requestUrlStr parameters:nil success:^(id  _Nullable responseObject) {
        
        if (responseObject[@"success"]) {
            
            NSDictionary * dataDict = responseObject[@"data"];
            
            BKUserStatusInfo * statusInfo = [BKUserStatusInfo currentUser];
            [statusInfo.realm  beginWriteTransaction];
            
            statusInfo.isLogin = YES;
            statusInfo.email = dataDict[@"email"];
            statusInfo.userId = [NSString stringWithFormat:@"%@",dataDict[@"id"]];
            statusInfo.job = dataDict[@"job"];
            statusInfo.nickName = dataDict[@"name"];
            statusInfo.userName = dataDict[@"username"];
            NSString * picture = [NSString stringWithFormat:@"%@%@_B.jpg",UserLogoPictureStr,dataDict[@"photo"]];
            statusInfo.photo = picture;
            statusInfo.visitorCode = dataDict[@"visitor_code"];
            [statusInfo.realm commitWriteTransaction];
             [[NSNotificationCenter defaultCenter]postNotificationName:UserDidLoginNotification object:nil];
            BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
            
            finishBlock(result,nil);
        }
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        finishBlock(nil,error);
        
    }];
    
    
}

//获取用户收藏列表
+(void)getUserCollectionListWithPageSize:(NSInteger)pageSize pageNo:(NSInteger)pageNo completeBlock:(BKUserCompleteBlock)completeBlock
{
    NSString *requestUrlStr = [BestKeepAPIStr stringByAppendingString:UserCollectionGoodsListStr];
    NSString * pageSizeStr = [NSString stringWithFormat:@"%ld",(long)pageSize];
    NSString * pageNoStr = [NSString stringWithFormat:@"%ld",(long)pageNo];
    NSDictionary *parameterDic = [NSDictionary dictionaryWithObjectsAndKeys:pageNoStr,@"pageno",pageSizeStr,@"pagesize", nil];
   
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:requestUrlStr parameters:parameterDic success:^(id  _Nullable responseObject) {
        
        NSDictionary * result_dic = responseObject;
        NSArray * tempList = [[result_dic objectForKey:@"data"] objectForKey:@"list"];
        BKUserCollectionGoodsModel * collectionGoodsModel = [[BKUserCollectionGoodsModel alloc]init];
        collectionGoodsModel.pageNo = [[result_dic objectForKey:@"data"]objectForKey:@"pageno"];
        collectionGoodsModel.total = [[result_dic objectForKey:@"data"]objectForKey:@"total"];
        NSMutableArray * goosListArray = [NSMutableArray array];
        NSMutableArray * goodsNoArr = [[NSMutableArray alloc] init];
        for (NSDictionary * dcit in tempList) {
            
            BKUserMyFavorGoodsModel * tempModel = [BKUserMyFavorGoodsModel mj_objectWithKeyValues:dcit];
            [goosListArray addObject:tempModel];
            [goodsNoArr addObject:tempModel.goods_no];
        }
        
        NSString * goods_nos = [goodsNoArr componentsJoinedByString:@","];
        __block NSArray * tempGoodsArr = goosListArray;
        
        [BKUserUnitRequestAPI goodsReservStatusWithGooodsNo:goods_nos completeBlock:^(id result, NSError *error) {
         
            if (error) {
                
                completeBlock?completeBlock(nil,error):nil;
            } else {
                
                NSMutableArray * dataArr = [NSMutableArray array];
                [result enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                    
                    for (BKUserMyFavorGoodsModel * favorModel in tempGoodsArr) {
                        
                        NSString * goodsNo = obj[@"goodsNo"];
                        if ([goodsNo isEqualToString:favorModel.goods_no]) {
                            
                            favorModel.status = obj[@"status"];
                            favorModel.amount = obj[@"amount"];
                            [dataArr addObject:favorModel];
                        }
                    }
                    
                }];
                
                collectionGoodsModel.list = dataArr;
                completeBlock(collectionGoodsModel,nil);
            }
        }];
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        
        if (error) {
            
            completeBlock(nil,error);
        }
    }];
}

//删除收藏列表的商品
+(void)deleteCollectionGoodsFromListWithCollectionId:(NSString *)collectionId completeBlock:(BKUserCompleteBlock)completeBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserColletionListDeleteGoodsStr];
    NSDictionary * paraDict = [NSDictionary dictionaryWithObjectsAndKeys:collectionId,@"data", nil];

    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paraDict success:^(id  _Nullable responseObject) {
     
        NSDictionary * dict = responseObject;
        BKUserRequestResultModel * resultModel = [BKUserRequestResultModel mj_objectWithKeyValues:dict];
        completeBlock(resultModel,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        if (error) {
            
            completeBlock(nil,error);
        }
        
    }];
}

//商品状态

+(void)goodsReservStatusWithGooodsNo:(NSString *)goodsNo completeBlock:(BKUserCompleteBlock)completeBlock
{
    NSString * requestUrlStr = [BestKeepAPIStr stringByAppendingString:UserGoodsReserveStatus];
    
    NSDictionary * paramaDcit = @{@"goods_nos":goodsNo};
    
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:requestUrlStr parameters:paramaDcit success:^(id  _Nullable responseObject) {
        
        if (responseObject) {
            
            NSArray * statuArr = [responseObject objectForKey:@"data"];
            completeBlock(statuArr,nil);
        }
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        if (error) {
            
            completeBlock(nil,error);
        }
    }];
}

//获取用户等级
+(void)getUserLeverOfVipWithResultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserLeverOfVipStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        
        NSDictionary * dict = responseObject;
        BKUserRequestResultModel * resultModel = [BKUserRequestResultModel mj_objectWithKeyValues:dict];
        if ([resultModel.success isEqualToString:@"1"]) {
            
            NSDictionary * dataDict = responseObject[@"data"];
            BKUserStatusInfo * statusInfo = [BKUserStatusInfo currentUser];
            [statusInfo.realm  beginWriteTransaction];
            
            statusInfo.level = dataDict[@"level"];
            NSString * levelNumStr = dataDict[@"levelNum"];
            statusInfo.levelNum = [NSString stringWithFormat:@"%d",[levelNumStr intValue]];
            statusInfo.vipFlag = dataDict[@"vipFlag"];
            statusInfo.realAuthStatus = dataDict[@"realAuthStatus"];
            
            [statusInfo.realm commitWriteTransaction];
        }
        resultBlock(resultModel,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        if (error) {
            
            resultBlock(nil,error);
        }
    }];
    
}

//修改用户昵称
+(void)modifyUserNickNameWithNewNickName:(NSString *)nickName resultBlcok:(BKUserCompleteBlock)resultBlock
{
   
    NSString * urlStr = [BestKeepAPIStrV2 stringByAppendingString:UserModifyNickNameStr];
    NSDictionary *dict = @{@"nickName":nickName};
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
       
        BKUserRequestResultModel * resultModel = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(resultModel,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlock(nil,error);
        
    }];
}

//上传用户图像
+(void)upLoadUserHeadImgeDataStr:(NSString *)imgDataStr resultBlock:(BKUserCompleteBlock)resultBlok
{
    
    NSString * urlStr = [UTOOUAPIStr stringByAppendingString:UserUpLoadHeadImgStr];
    NSDictionary * paraDict = @{@"photo":imgDataStr};
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paraDict success:^(id  _Nullable responseObject) {
        
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        
        NSDictionary * dict = responseObject[@"data"];
        result.data = dict[@"url"];
        resultBlok(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlok(nil,error);
    }];
    
}

//上传用户意见反馈图片
+(void)upLoadFeedBackImgData:(NSData *)imgData resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserFeedbackUploadImg];
    BKFileObject * file = [[BKFileObject alloc]init];
    file.name = @"img";
    file.fileName = @"image.jpg";
    file.data = imgData;
    [[RequestManager manager]bkUploadRequest:RequestMethodPost URLString:urlStr parameters:nil file:file success:^(id  _Nullable responseObject) {
       
        NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        BKUserRequestResultModel * resultModel = [BKUserRequestResultModel mj_objectWithKeyValues:dataDict];
        NSDictionary * dict = dataDict[@"data"];
        resultModel.data = dict[@"url"];
        resultBlock(resultModel,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
     
        resultBlock(nil,error);
    }];
}

//上传用户反馈信息
+(void)upLoadFeedBackInfoWithParameterDict:(NSDictionary *)dict resultBlock:(BKUserCompleteBlock)resultBlcok
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserFeedbackUpLoad];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
        
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlcok(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
      
        
            resultBlcok(nil,error);
        
    }];
    
}

//发送短信验证码
+(void)sendMessageWithMobileNum:(NSString *)mobileStr resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString *urlStr =[UserPassPortStr stringByAppendingString:UserGetSMSCodeStr];
    
    BKUserMobileConfigInfo * config = [[BKUserMobileConfigInfo alloc] init];
    
    
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
    
    [dic1 setValue:mobileStr forKey:@"mobile"];
    [dic1 setValue:@"10" forKey:@"device"];
    [dic1 setValue:@"" forKey:@"imgVCode"];
    [dic1 setValue:@"" forKey:@"imgVCodeKey"];
    [dic1 setValue:config.device_udid forKey:@"imei"];
    
    NSString * time = [Sign getSystemTime];
    
    NSString * signName = [Sign sign:dic1 time:time];
    
    [dic1 setValue:time forKey:@"time"];
    [dic1 setValue:signName forKey:@"sign"];
   
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic1 success:^(id  _Nullable responseObject) {
       
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
    
}

//验证短信验证码
+(void)verifySMSVerificationcodeWithCodeStr:(NSString *)codeStr accountNum:(NSString *)accountNumStr resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UserCheckSMSCodeStr];
    NSMutableDictionary * paramDict = [[NSMutableDictionary alloc] init];
    [paramDict setObject:accountNumStr forKey:@"mobile"];
    [paramDict setObject:codeStr forKey:@"code"];
  
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paramDict success:^(id  _Nullable responseObject) {
       
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
      
        resultBlock(nil,error);
    }];
}

//用户注册
+(void)userRegisterWithAccount:(NSString *)account pwdStr:(NSString *)pwdStr smsCodeStr:(NSString *)smsCodeStr secreatCode:(NSString *)secreatCode resultBlock:(BKUserCompleteBlock)resultBlock;
{
    if (secreatCode == nil) {
        
        secreatCode = @"";
    }
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UserRegisterStr];
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:account forKeyPath:@"username"];
    [dict setValue:pwdStr forKeyPath:@"password"];
    [dict setValue:@"10" forKeyPath:@"source"];
    [dict setValue:@"" forKeyPath:@"visitor"];
    [dict setValue:secreatCode forKeyPath:@"cipher"];
    [dict setValue:smsCodeStr forKey:@"smsVCode"];
    
    NSString * time = [Sign getSystemTime];
    NSString *sign = [Sign sign:dict time:time];
    [dict setValue:sign forKeyPath:@"sign"];
    [dict setValue:time forKeyPath:@"time"];

    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
    
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
    
}
//用户获取图片验证码 (返回随机产生的唯一标示符)
+(NSString *)getUserImgCodeAndUniqueIdWithBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [UserGetImgCodeVerifyStr stringByAppendingString:UserGetImgVerifyCode];
    NSString *uuid = [NSString stringWithFormat:@"%d",arc4random()];
    NSDictionary  *paraDict = [NSDictionary dictionaryWithObjectsAndKeys:
                               uuid,@"key",
                               @"3600",@"time",
                               @"3",@"source",//ios-p
                               //@"2",@"source",//ios
                               @"100",@"width",
                               @"40",@"height",
                               @"",@"sign",
                               @"4",@"len", nil];
    
    NSMutableURLRequest *request = [[RequestManager manager] HTTPRequestWithMethod:RequestMethodPost URLString:urlStr parameters:paraDict error:nil];
    
    [[RequestManager manager] dataWithRequest:request responseConfig:^id<AFURLResponseSerialization> _Nullable{
        
        AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer];
        return serializer;
        
    } completionHandler:^(NSURLResponse * _Nullable response, id  _Nullable responseObject, NSError * _Nullable error) {
        
        NSDictionary * dict = @{@"imgCodeKey":uuid,@"data":responseObject};
        resultBlock (dict,error);
        
    }];

    return uuid;
}

//根据图片验证码获取短信验证码
+(void)getMessageCodeWithDataDict:(NSDictionary *)dataDict imgCodeGenerationCode:(NSString *)gerationCodeStr block:(BKUserCompleteBlock)resultBlock
{
    // ------请求短信验证码
    NSString *udid = [[[BKUserMobileConfigInfo  alloc]init] device_udid];// 设备号
    NSString * time = [Sign getSystemTime];
    
    NSString *mobileNumber = [NSString stringWithFormat:@"%@",dataDict[@"mobileNum"]];
    NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
    NSString * imgCodeStr = dataDict[@"imgCodeStr"];
    
    [dic1 setValue:mobileNumber forKey:@"mobile"];
    [dic1 setValue:@"10" forKey:@"device"];
    [dic1 setValue:imgCodeStr forKey:@"imgVCode"];
    [dic1 setValue:gerationCodeStr forKey:@"imgVCodeKey"];
    [dic1 setValue:udid forKey:@"imei"];
    
     NSString * signName = [Sign sign:dic1 time:time];
    
    [dic1 setValue:time forKey:@"time"];
    [dic1 setValue:signName forKey:@"sign"];
    
    NSString * url = [UserPassPortStr stringByAppendingString:UserGetSMSCodeStr];
 
    [[RequestManager  manager]bkDataRequest:RequestMethodPost URLString:url parameters:dic1 success:^(id  _Nullable responseObject) {
        
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        
        resultBlock(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
}

//用户获取图片验证码
+(void)getUserImgCodeWithBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [UserGetImgCodeVerifyStr stringByAppendingString:UserGetImgVerifyCode];
    //BKUserMobileConfigInfo * config = [[BKUserMobileConfigInfo alloc]init];
    //NSString * uuId = config.device_udid;
    NSString *uuid = [NSString stringWithFormat:@"%d",arc4random()];
    NSDictionary  *paraDict = [NSDictionary dictionaryWithObjectsAndKeys:
                               uuid,@"key",
                               @"3600",@"time",
                               @"3",@"source",//ios-p
                               //@"2",@"source",//ios
                               @"100",@"width",
                               @"40",@"height",
                               @"",@"sign",
                               @"4",@"len", nil];
    
    NSMutableURLRequest *request = [[RequestManager manager] HTTPRequestWithMethod:RequestMethodPost URLString:urlStr parameters:paraDict error:nil];
    
    [[RequestManager manager] dataWithRequest:request responseConfig:^id<AFURLResponseSerialization> _Nullable{
        
        AFHTTPResponseSerializer *serializer = [AFHTTPResponseSerializer serializer];
        return serializer;
        
    } completionHandler:^(NSURLResponse * _Nullable response, id  _Nullable responseObject, NSError * _Nullable error) {
        
        NSDictionary * dict = @{@"imgCodeKey":uuid,@"data":responseObject};
        resultBlock (dict,error);
        
    }];
    
}

//找回密码第一步
+(void)findPwdFirstStepWithAccount:(NSString *)accountStr imgCodeStr:(NSString *)imgCodeStr imgCodeKey:(NSString *)imgCodekey resultBlock:(BKUserCompleteBlock)resultBlock;
{
    
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UserFindPwdStr];
    NSMutableDictionary * paramDict = [[NSMutableDictionary alloc] init];
    [paramDict setObject:accountStr forKey:@"username"];
    [paramDict setObject:imgCodeStr forKey:@"imgVCode"];
    [paramDict setObject:imgCodekey forKey:@"imgVCodeKey"];
    
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paramDict success:^(id  _Nullable responseObject) {
        
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        
        resultBlock(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlock (nil,error);
    }];
    
}

//找回密码 获取验证码
+(void)findPwdGetSMSCodeStrWithAccount:(NSString *)accountStr resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UserFindPwdGetSMSCodeStr];
    NSDictionary *dic = @{ @"username": accountStr};

    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dic success:^(id  _Nullable responseObject) {
       
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlock(nil,error);
    }];
    
}

//找回密码 重置新的密码
+(void)findPwdAndResetNewPwdWithAccount:(NSString *)accountStr newPwd:(NSString *)pwd passDataStr:(NSString *)passData resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UserRetireNewPwdStr];
    NSDictionary * paraDict = @{@"password":pwd,
                                @"idenKey":passData,
                                @"mobile":accountStr,
                              };

    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paraDict success:^(id  _Nullable responseObject) {
        
   
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
       
        resultBlock(nil,error);
    }];
    
}

//个人信息 修改密码
+(void)modifyNewPwdWithDict:(NSDictionary *)dict resultBlock:(BKUserCompleteBlock)resultBlcok
{
  
    NSString * urlStr = [UserPassPortStr stringByAppendingString:UeserModifyPwdStr];
   
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
        
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlcok(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
      
        resultBlcok(nil,error);
    }];

}

//三方登录相关接口
//联合登录接口，即登录页面QQ与微信中接口
+(void)checkThirdAccount:(NSDictionary *)dictionary mycallBack:(BKUserCompleteBlock)resultBlock
{
    NSString *urlStr = [UserPassPortStr stringByAppendingString:UserOtherPlaformatLoginAPIStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dictionary success:^(id  _Nullable responseObject) {
        
        resultBlock(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
      
        resultBlock(nil,error);
    }];
    
}
//个人信息中第三方登录是否绑定
+(void)userInfoThirdAccount:(NSDictionary *)dict mycallBack:(BKUserCompleteBlock)resultBlock{
    
    NSString *urlStr = [BestKeepAPIStrV2 stringByAppendingString:UserIsBindinOtherPlaFormatAPIStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
    
        resultBlock(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
    
}

//个人信息中第三方移除绑定
+(void)userInfoRemoveThirdAccount:(NSDictionary *)dict mycallBack:(BKUserCompleteBlock)resultBlock
{
    NSString *urlStr = [BestKeepAPIStrV2 stringByAppendingString:UserRemoveRealationShipAPIStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
      
        resultBlock(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
}

//绑定登录接口即绑定登录页面中所用的接口
+(void)bindOpenAccount:(NSDictionary *)dict mycallBack:(BKUserCompleteBlock)resultBlock
{
    NSString *urlStr = [UserPassPortStr stringByAppendingString:UserUserInfoBindingAPIStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {

        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        
        resultBlock(result,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
  
        resultBlock(nil,error);
    }];
    
}

//个人信息中解绑后再绑定的接口
+(void)userInfoBindAccount:(NSDictionary *)dict mycallBack:(BKUserCompleteBlock)resultBlock
{
    NSString *urlStr = [BestKeepAPIStrV2 stringByAppendingString:UserBindingAfterRemoveBindingAPIStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:dict success:^(id  _Nullable responseObject) {
        
        resultBlock(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
    
        resultBlock(nil,error);
    }];
    
}



//实名认证上传图片
+(void)upLoadRealNameAuthImgData:(NSData *)imgData resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserUploadIdCardImgStr];
    BKFileObject * file = [[BKFileObject alloc]init];
    file.name = @"picture";
    file.fileName = @"image.png";
    file.data = imgData;
    [[RequestManager manager]bkUploadRequest:RequestMethodPost URLString:urlStr parameters:nil file:file success:^(id  _Nullable responseObject) {
    
        NSDictionary * dataDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        BKUserRequestResultModel * resultModel = [BKUserRequestResultModel mj_objectWithKeyValues:dataDict];
        resultModel.data = dataDict[@"url"];
        resultBlock(resultModel,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlock(nil,error);
    }];
    
}

//提交认证信息
+(void)upLoadRealNameAuthPersonalInfoWithInfoDict:(NSDictionary *)infoDict resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:CertificationInfoStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:infoDict success:^(id  _Nullable responseObject) {
       
        BKUserRequestResultModel * result = [BKUserRequestResultModel mj_objectWithKeyValues:responseObject];
        resultBlock(result,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
       
        resultBlock(nil,error);
    }];
    
}

//获取认证信息
+(void)getUserAuthRealNameDeatailWithCompleteBlock:(BKUserCompleteBlock)resultBlock
{
    
    NSString *urlStr = [BestKeepAPIStr stringByAppendingString:UserGetCertifyDetailStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
       
        resultBlock(responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
}

//我的账户详情
+(void)getUserAccountDetailWithBlock:(BKUserCompleteBlock)resultBlock
{
   
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserMyAccountDeatailStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
   
        resultBlock (responseObject,nil);
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock (nil,error);
    }];
    
}

//获得想要咨询的订单
+(void)getWantToAskOrderWithParaDict:(NSDictionary *)paraDict resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserCheckOrderStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:paraDict success:^(id  _Nullable responseObject) {
        
        resultBlock(responseObject,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
}

//获取未读信息数
+(void)getUnreadMessageNumberWithUserid:(NSString *)userId resultBlock:(BKUserCompleteBlock)resultBlock
{
    NSString * urlStr = [BestKeepAPIStr stringByAppendingString:UserGetNoReadMessageNumStr];
    [[RequestManager manager]bkDataRequest:RequestMethodPost URLString:urlStr parameters:nil success:^(id  _Nullable responseObject) {
        
        resultBlock(responseObject,nil);
        
    } failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
        resultBlock(nil,error);
    }];
}

@end
